package com.oa.util;

import java.sql.Date;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;

import org.apache.naming.java.javaURLContextFactory;

public class MyDateUtil {

	/**
	 * sdf可为"yyyy-MM-dd HH:mm:ss"和"yyyy-MM-dd" 
	 * @param dateString
	 * @return
	 */
	public static Date String2SQLDate(String dateString) {
		String str="1998-28-25 10:30:00";
		SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		java.util.Date d=null;
		try {
			d=format.parse(str);
		} catch (Exception e) {
			e.printStackTrace();
		}
		java.sql.Date date=new java.sql.Date(d.getTime());
		return date;
	}

	public static java.sql.Timestamp strToTimeStamp(String strDate,String dateFormat){
		SimpleDateFormat sf=new SimpleDateFormat(dateFormat);
		java.util.Date date=null;
		try {
			date=sf.parse(strDate);
		} catch (Exception e) {
			e.printStackTrace();
		}

	    java.sql.Timestamp dateSQL = new java.sql.Timestamp(date.getTime());
	    return dateSQL;
	}

}
